public class Test {
    public static SingleLinkedList.ListNode mergeTwoLists(SingleLinkedList.ListNode headA,
                                                          SingleLinkedList.ListNode headB){
        SingleLinkedList.ListNode newH = new SingleLinkedList.ListNode(-1);
        SingleLinkedList.ListNode tmp = newH;
        while (headA != null && headB != null){
            if(headA.val < headB.val){
                tmp.next = headA;
                headA = headA.next;
                tmp = tmp.next;
            }else{
                tmp.next = headB;
                headB = headB.next;
                tmp = tmp.next;
            }
        }
        if(headA == null){
            tmp.next = headB;
        }
        if(headB == null){
            tmp.next = headA;
        }
        return newH.next;
    }

    public static void main2(String[] args) {
        SingleLinkedList list1 = new SingleLinkedList();
        list1.addLast(1);
        list1.addLast(3);
        list1.addLast(5);
        list1.addLast(9);
        list1.addLast(12);
        list1.addLast(23);

        SingleLinkedList list2 = new SingleLinkedList();
        list2.addLast(2);
        list2.addLast(6);
        list2.addLast(8);
        list2.addLast(21);

        SingleLinkedList.ListNode newHead = mergeTwoLists(list1.head,list2.head);
        list1.display(newHead);
    }

    public static void main1(String[] args) {
        SingleLinkedList list = new SingleLinkedList();
        list.addLast(1);
        list.addLast(2);
        list.addLast(3);
        list.addLast(4);
        list.addLast(4);
        list.addLast(5);
        list.addLast(6);
        list.display();
        System.out.println("=======");
        list.addIndex(4,45);
        list.display();
        System.out.println("=======");
        list.removeAllKey(4);
        list.display();
        System.out.println("=======");
        list.reverseList();
        list.display();
        System.out.println("=======");
        SingleLinkedList.ListNode ret1 = list.middleVal();
        System.out.println(ret1.val);
        System.out.println("=======");

        System.out.println(list.kthToLast(7));
    }
}
